<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>
${nickName}绑定成功
<img src="${avatarUrl}">
<a href="https://gitee.com/oauth/authorize?client_id=0d844c04bebb913e0c7d6cdbf9122430fd2bb1c950f0c96b5d896fad172ca52e&redirect_uri=http://localhost:8080/callbackCode.do&response_type=code">gitee账号绑定</a>
<h1>----------------------</h1>
<form action="/list.do">

    报销人<input name="name" value="${query.name}"><br>

    报销类型 <select name="applyTypeId">
    <option value="">请选择</option>
    <c:forEach items="${typeList}" var="t">
        <option    ${query.applyTypeId == t.id ? 'selected':''}  value="${t.id}">${t.name}</option>
    </c:forEach>
</select><br>
    报销状态 <select name="status">
    <option value="">请选择</option>
    <option   ${query.status == 1 ? 'selected':''} value="1">未报销</option>
    <option ${query.status == 2 ? 'selected':''} value="2">已报销</option>

</select><br>

    <input type="submit" value="查询">
    <input type="button" value="批量删除" onclick="batchDel()">
    <a href="/addPage.do">添加</a>
    <table>
        <tr>
            <td>操作</td>
            <td>id</td>
            <td>图片</td>
            <td>报销类型</td>
            <td>金额</td>
            <td>报销人</td>
            <td>状态</td>
            <td>报销日期</td>
            <td>操作</td>
        </tr>

        <c:forEach items="${pageInfo.list}" var="a">
            <tr>
                <td><input type="checkbox" name="delId" value="${a.id}"></td>
                <td>${a.id}</td>
                <td><img  style="height: 50px;width: 50px" src="${a.url}"> ${a.name}</td>
                <td>${a.applyTypeName}</td>
                <td>${a.amount}</td>
                <td>${a.name}</td>
                <td>${a.status == 1 ? '未报销':'已报销'}</td>
                <td>${a.applyDate}</td>
                <td><input type="button" ${a.status !=1 ? 'disabled':''} onclick="completeStatus(${a.id})" value="完成报销"></input>
                    <input type="button" onclick="del(${a.id})" value="删除">
                </td>
            </tr>
        </c:forEach>
        <tr >
            <td> <button name="pageNum" value="1">首页</button> </td>
            <td> <button name="pageNum" value="${pageInfo.prePage}">上页</button> </td>
            <td> <button name="pageNum" value="${pageInfo.nextPage}">下页</button> </td>
            <td> <button name="pageNum" value="${pageInfo.pages}">尾页</button> </td>
        </tr>
    </table>

</form>

</body>
<script>

    function completeStatus(id) {
        window.location.href = '/complete.do?id=' + id
    }

    function del(id) {
        window.location.href = '/del.do?id=' + id
    }

    function batchDel() {
        var ids = [];
        $('[name=delId]:checked').each(
          function (){

              let attr = this.value;
              console.log(attr)

              let id = $(this).val();
              console.log(id)

              ids.push(id)
          }
        )

        if (ids.length == 0){

            alert("请选择数据！")
            return;
        }
        // window.location.href = '/del.do?id=' + ids

    }
</script>
</html>